<?php
namespace app\my\model;
use app\base\model\BaseModel;
use think\Db;
use think\facade\Log;
/**
 * 
 */
class AttentionModel extends BaseModel
{
	//取消关注
	public function attention_cancels($data){
		$up['isMuAttention'] =1;
		$upa['status'] =2;
		$where['mutualOpenid']=$data['mutualOpenid'];
		$where['passOpenid']=$data['passOpenid'];
		$whereor['mutualOpenid']=$data['passOpenid'];
		$whereor['passOpenid']=$data['mutualOpenid'];
		$res = Db::name('attention')->where($where)->whereOr($whereor)->update($up);
		$res = Db::name('attention')->where($where)->update($upa);
		return $res;
	}

	//列表
	public  function list($data){
		$limit =20;
		$pre=($data['page']-1)*$limit;
		if(isset($data['Usernickname'])&&!empty($data['Usernickname'])){
			$where=[
				["a.mutualOpenid",'eq',$data['Openid']],
				["u.Usernickname",'like',$data['Usernickname']."%"],
				["a.status",'eq',1],
			];
		}else{
			$where['a.mutualOpenid']=$data['Openid'];
			$where['a.status']=1;
		}
		$res = Db::name('attention')->alias('a')->field('u.Userimg,u.Usernickname,u.Userid,u.Openid,a.isMuAttention')->join('userinfo u','u.Openid = a.mutualOpenid')->where($where)->limit($pre,$limit)->select();
		return $res;
	}
}